package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.limao.DBDataClass.HomeColumClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Tool.CacheClass;

public class HomeMenuProvider {

	private static HomeMenuProvider instance;

	public static HomeMenuProvider getInstance() {
		if(instance==null) instance=new HomeMenuProvider();
		return instance;
	}
	
  
	private HomeMenuProvider() {

	}

	//新鲜宝   
	private HomeColumClass encapOrderData(ResultSet rs) throws Exception{
			
		HomeColumClass orderData = new HomeColumClass();

		orderData.columid=rs.getString("columid");
		orderData.columname=rs.getString("columname");
		orderData.isdefault=rs.getString("isdefault");
		orderData.sortvalue=rs.getString("sortvalue");
		orderData.state=rs.getString("state");
		
	
		return orderData;
	}
			
	
	public ArrayList<HomeColumClass> Load_HomeColum_All()
	{
		ArrayList<HomeColumClass> list = new ArrayList<HomeColumClass>();
		HomeColumClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select * from cd_sys_homecolum where state>0 order by sortvalue asc ");
				rs = pstmt.executeQuery();
				while (rs.next()) {
					tmp = encapOrderData(rs);
					list.add(tmp);
				}

			} catch (Exception e) {
				e.printStackTrace();
				list .clear();
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}
			return list;
	}
	
	public HomeColumClass Load_HomeColum_byColumid(String Columid)
	{
		
		HomeColumClass tmp = null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select * from cd_sys_homecolum where columid=? ");
				pstmt.setInt(1, CacheClass.getIntValue(Columid));
				rs = pstmt.executeQuery();
				if (rs.next()) {
					tmp = encapOrderData(rs);
				}

			} catch (Exception e) {
				e.printStackTrace();
				tmp=null;
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}
			return tmp;
	 }
	    
}
